<template>
	<view class="wrap">
		<view class="top"></view>
		<view class="content">
			<view class="title">用户注册</view>
			<input class="u-border-bottom"  v-model="email" placeholder="邮箱" />
			<input class="u-border-bottom" type="text" v-model="name" placeholder="昵称" />
			<input class="u-border-bottom" type="password" v-model="password" placeholder="密码" />
			<input class="u-border-bottom" type="password" v-model="password_confirmation" placeholder="确认密码" />
	
			<button @tap="submit" :style="[inputStyle]" class="getCaptcha">注册</button>
			<view class="alternative">
				<view class="password" @click="toLogin">已有帐号，去登陆</view>
				<view class="issue" @click="toHome">返回首页</view>
			</view>
		</view>
	<tab-bar></tab-bar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: '',
				email: '',
				password:'',
				password_confirmation: '',
			}
		},
		computed: {
			inputStyle() {
				let style = {};
				if(this.$u.test.email(this.email) && this.name && this.password && this.password == this.password_confirmation) {
					style.color = "#fff";
					style.backgroundColor = this.$u.color['warning'];
				}
				return style;
			}
		},
		methods: {
			async submit(){
				//表单验证
				if(!this.name || !this.$u.test.email(this.email) || !this.password || !this.password_confirmation) return
				//注册提交参数
				const params = {
					name:this.name,
					email:this.email,
					password:this.password,
					password_confirmation:this.password_confirmation
				}
				//登陆接口AIP数据
				
				const regRes = await this.$u.api.register(params)
				console.log(regRes)
				this.$u.toast('注册成功')
				setTimeout(()=>{
					this.$u.route({
						type:'reLaunch',    //reLaunch 可以跳转普通页和tabbar
						url:'pages/auth/login'
					})
				},1000)
			},
			toLogin(){
				this.$u.route({
					type:'redirect', 
					url:'pages/auth/login'
				})
			},
			toHome(){
				this.$u.route({
					type:'switchTab', 
					url:'pages/index/index'
				})
			},
			//page.josn自定义图标跳转
			onNavigationBarButtonTap(e) {
				console.log(e)
				if (e.index == 1) {undefined
					this.$u.route({
						type:'switchTab', 
						url:'pages/cate/cate'
					})
				};

				if (e.index == 0) {undefined
					this.$u.route({
						type:'switchTab', 
						url:'pages/index/index'
					})
				}
			    
			},
		},
		
	}
</script>

<style lang="scss" scoped>
.u-border-bottom {
	margin-top: 40rpx !important;
}	
.wrap {
	font-size: 28rpx;
	.content {
		width: 600rpx;
		margin: 80rpx auto 0;

		.title {
			text-align: left;
			font-size: 60rpx;
			font-weight: 500;
			margin-bottom: 100rpx;
		}
		input {
			text-align: left;
			margin-bottom: 10rpx;
			padding-bottom: 6rpx;
		}
		.tips {
			color: $u-type-info;
			margin-bottom: 60rpx;
			margin-top: 8rpx;
		}
		.getCaptcha {
			background-color: rgb(253, 243, 208);
			color: $u-tips-color;
			border: none;
			font-size: 30rpx;
			padding: 12rpx 0;
			
			&::after {
				border: none;
			}
		}
		.alternative {
			color: $u-tips-color;
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
		}
	}

}
</style>
